package com.andy.customerService.controller;


import com.andy.customerService.entity.Org;
import com.andy.customerService.pojo.request.OrgRequestParam;
import com.andy.customerService.service.OrgService;
import com.andy.customerService.vo.JsonBaseResult;
import com.andy.customerService.vo.JsonPageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 组织机构表 前端控制器
 * </p>
 *
 * @author Andy
 * @since 2021-12-27
 */
@RestController
@RequestMapping("/org")
public class OrgController {

    @Autowired
    private OrgService orgService;

    /**
     * 添加组织结构
     * @param org
     */
    @PostMapping
    public void addOrg(@RequestBody Org org) {
        orgService.addOrg(org);
    }

    /**
     * 根据id修改组织机构
     * @param org
     */
    @PutMapping
    public void editOrgById(@RequestBody Org org){
        orgService.editOrgById(org);
    }

    /**
     * 根据id删除组织机构
     * @param id
     */
    @DeleteMapping
    public void deleteOrgById(@RequestParam("id")Long id){
        orgService.deleteOrgById(id);
    }

    /**
     * 根据id查询组织机构
     * @param id
     */
    @GetMapping
    public JsonBaseResult<Object> queryOrgById(@RequestParam("id")Long id){
        return orgService.queryOrgById(id);
    }

    /**
     * 根据条件分页查询组织机构
     * @param requestParam
     */
    @PostMapping("/list")
    public JsonPageResult<Object> queryOrgByParam(@Valid @RequestBody OrgRequestParam requestParam){
        return orgService.queryOrgByParam(requestParam);
    }

}

